package com.mushuilingfeng.ddd.user.controller;

import com.mushuilingfeng.ddd.user.bo.MobileLoginBO;
import com.mushuilingfeng.ddd.user.bo.UserPasswordLoginBO;
import com.mushuilingfeng.ddd.user.service.IUserLoginService;
import com.mushuilingfeng.ddd.user.vo.UserLoginResult;
import com.mushuilingfeng.spring.common.BaseResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 沐水淋风
 * @date 2024/9/29
 */
@RestController
@RequestMapping("userLogin")
@AllArgsConstructor
@Tag(name = "用户登录")
public class UserLoginController {
    private final IUserLoginService userLoginService;
    
    @GetMapping("/passwordLoginVerifyCode/{clientId}")
    public BaseResult<String> getPasswordLoginVerifyCode(@PathVariable String clientId) {
        return BaseResult.success(userLoginService.getPasswordLoginVerifyCode(clientId));
    }
    
    @PostMapping("/passwordLogin")
    public BaseResult<UserLoginResult> passwordLogin(@RequestBody @Validated UserPasswordLoginBO bo) {
        return BaseResult.success(userLoginService.passwordLogin(bo));
    }
    
    @PostMapping("/sendMobileLoginVerifyCode/{tel}")
    public BaseResult<Void> sendMobileLoginVerifyCode(@PathVariable String tel) {
        userLoginService.sendMobileLoginVerifyCode(tel);
        return BaseResult.success(null);
    }
    
    @PostMapping("/mobileLogin")
    public BaseResult<UserLoginResult> mobileLogin(@RequestBody @Validated MobileLoginBO bo) {
        return BaseResult.success(userLoginService.mobileLogin(bo));
    }
    
}
